using System;
using SMS.SMPPClient.PDU;

namespace SMS.SMPPClient.PDU.Outgoing
{
    /// <summary>
    /// Provides some common attributes for data_sm, query_sm, submit_sm, submit_multi,
    /// cancel_sm, and replace_sm.
    /// </summary>
    public abstract class MessageLCD6 : SMPPRequest
    {
        protected TONType _SourceAddrTON;
        protected NPIType _SourceAddrNPI;
        protected string _SourceAddress;

        protected const int ADDRESS_LENGTH = 20;
        protected const int MSG_LENGTH = 64;
        protected const int SERVICE_TYPE_LENGTH = 5;

        /// <summary>
        /// Groups construction tasks for subclasses.
        /// </summary>
        /// <param name="sourceAddrTON">The type of number of the source address.</param>
        /// <param name="sourceAddrNPI">The number plan indicator of the source
        /// address.</param>
        /// <param name="sourceAddress">The source address.</param>
        protected MessageLCD6(TONType sourceAddrTON,
                            NPIType sourceAddrNPI, string sourceAddress)
        {
            _SourceAddrTON = sourceAddrTON;
            _SourceAddrNPI = sourceAddrNPI;

            if (sourceAddress != null)
            {
                if (sourceAddress.Length <= ADDRESS_LENGTH)
                    _SourceAddress = sourceAddress;
                else
                    throw new ArgumentOutOfRangeException(
                        "Source Address must be <= " + ADDRESS_LENGTH + " characters.");
            }
            else
                _SourceAddress = "";
        }
    }
}
